package com.seckill.promotion.strategy.scope;

import com.seckill.api.client.item.ItemClient;
import com.seckill.api.dto.item.ItemSimpleInfoDTO;
import com.seckill.common.exceptions.BizIllegalException;
import com.seckill.common.utils.CollUtils;
import com.seckill.promotion.constants.ScopeType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Component(ScopeType.ITEM_HANDLER_NAME)
public class ItemScopeNameHandler implements com.seckill.promotion.strategy.scope.ScopeNameHandler {

    private final ItemClient itemClient;

    @Override
    public List<String> getNameByIds(List<Long> scopeIds) {
        List<ItemSimpleInfoDTO> infos = itemClient.getSimpleInfoList(scopeIds);
        if (CollUtils.isEmpty(infos)) {
            throw new BizIllegalException("商品信息不存在");
        }
        return infos.stream().map(ItemSimpleInfoDTO::getName).collect(Collectors.toList());
    }
}
